using System;
using System.Collections.Generic;
using UnityEngine;

[Serializable]
public class StarterPack
{
	public string eventID;

	public string groupID;

	public string packID;

	public string iapID;

	public int profitPercent;

	public int salePercent;

	public int availabilityTime;

	public float weight;

	public List<StarterPackReward> rewards;

	public string ID
	{
		get
		{
			return eventID + "_" + packID;
		}
	}

	public bool availableForPurcase
	{
		get
		{
			return !purchased && JSONManager.Instance.ServerTimeLoad() && availableUntil > JSONManager.Instance.GetServerTime();
		}
	}

	public int availableUntil
	{
		get
		{
			return BCWStorage.Get<int>(ID + "_availableUntil");
		}
		set
		{
			BCWStorage.Set(ID + "_availableUntil", value, true);
		}
	}

	public bool purchased
	{
		get
		{
			return BCWStorage.Get<bool>(eventID + "_purchased");
		}
		set
		{
			BCWStorage.Set(eventID + "_purchased", value, true);
		}
	}

	public bool setAvailableWithNoInternet
	{
		get
		{
			return BCWStorage.Get<bool>(ID + "_setAvailableWithNoInternet");
		}
		set
		{
			BCWStorage.Set(ID + "_setAvailableWithNoInternet", value, true);
		}
	}

	public int setAvailableTime
	{
		get
		{
			return BCWStorage.Get<int>(ID + "_setAvailableTime");
		}
		set
		{
			BCWStorage.Set(ID + "_setAvailableTime", value, true);
		}
	}

	public bool IsGood()
	{
		int num = 0;
		int num2 = 0;
		foreach (StarterPackReward reward in rewards)
		{
			if (reward.rewardGroup == StarterPackRewardGroup.Product)
			{
				num++;
				if (reward.GetProduct() == null)
				{
					num2++;
				}
			}
		}
		bool result = true;
		if (num < 2)
		{
			if (num2 > 0)
			{
				result = false;
			}
		}
		else if (num2 > 2)
		{
			result = false;
		}
		return result;
	}

	public bool SetAvailable()
	{
		if (purchased)
		{
			BCWDebug.LogError("StarterPack " + ID + " allready purchased! It can't be set as available!");
			return false;
		}
		if (!JSONManager.Instance.ServerTimeLoad())
		{
			BCWDebug.LogError("StarterPack " + ID + " set available with no internet!");
			setAvailableWithNoInternet = true;
			return false;
		}
		setAvailableWithNoInternet = false;
		setAvailableTime = JSONManager.Instance.GetServerTime();
		availableUntil = JSONManager.Instance.GetServerTime() + availabilityTime;
		Dictionary<string, string> dictionary = new Dictionary<string, string>();
		dictionary.Add(InAppShop.currentGamerType.ToString(), ID + "_Available");
		FlurryWrapper.LogEvent(FlurryWrapper.EV_STARTER_PACKS_STATS, dictionary);
		return true;
	}

	public override bool Equals(object obj)
	{
		if (obj == null)
		{
			return false;
		}
		return ID == ((StarterPack)obj).ID;
	}

	public void Init()
	{
		foreach (StarterPackReward reward in rewards)
		{
			reward.starterPack = this;
		}
	}

	public void GiveRewards()
	{
		if (purchased)
		{
			BCWDebug.LogError("StarterPack " + ID + " allready purchased!");
			return;
		}
		Dictionary<string, string> dictionary = new Dictionary<string, string>();
		dictionary.Add(InAppShop.currentGamerType.ToString(), ID + "_Purchased");
		FlurryWrapper.LogEvent(FlurryWrapper.EV_STARTER_PACKS_STATS, dictionary);
		Init();
		foreach (StarterPackReward reward in rewards)
		{
			reward.GiveReward(Vector3.zero);
		}
		purchased = true;
	}
}
